import 'package:flutter/material.dart';
import 'package:flutterproject/mvvm/base/base_state.dart';
import 'package:flutterproject/page/setting/children/child_account/controller/child_account_controller.dart';
import 'package:flutterproject/util/extension/extension_util.dart';
import 'package:flutterproject/util/margin_padding_util.dart';
import 'package:flutterproject/widget/app_bar_common.dart';
import 'package:flutterproject/widget/button_common.dart';
import 'package:flutterproject/widget/text/text_common.dart';
import 'package:get/get.dart';

class ChildAccountPage extends BaseState<ChildAccountController> {
  @override
  ChildAccountController initController() => ChildAccountController();

  @override
  Widget initView(BuildContext context) {
    return Container(
      width: Get.width,
      height: Get.height,
      color: Color(0xFFF6F6F6),
      child: Column(
        children: [
          Expanded(
            child: Column(
              children: [
                AppBarCommon(title: "子账号"),
                if (controller.childAccountListBean?.subType == 1)
                  Expanded(
                    child: Container(
                      width: Get.width,
                      height: Get.height,
                      margin: MarginPaddingUtil.symmetric(
                          vertical: 23, horizontal: 20),
                      padding: MarginPaddingUtil.symmetric(
                          vertical: 42, horizontal: 37),
                      decoration: BoxDecoration(
                          color: Colors.white,
                          borderRadius: BorderRadius.circular(20.width)),
                      child: Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
                          TextCommon(
                            "已绑定子账号",
                            size: 28.sp,
                            fontWeight: FontWeight.bold,
                          ),
                          Expanded(
                            child: ListView.separated(
                              shrinkWrap: true,
                              itemCount: controller.childAccountListBean
                                      ?.subAccounts?.length ??
                                  0,
                              itemBuilder: (context, index) => TextCommon(
                                controller.childAccountListBean!
                                        .subAccounts![index].mobile ??
                                    "",
                                size: 28.sp,
                                fontWeight: FontWeight.w500,
                              ),
                              separatorBuilder: (context, index) => SizedBox(
                                height: 60.height,
                                child: Divider(
                                  color: Color(0xFFE7E7E7),
                                  height: 1.width,
                                ),
                              ),
                            ),
                          ),
                        ],
                      ),
                    ),
                  ),
                if (controller.childAccountListBean?.subType == 2)
                  Container(
                    width: Get.width,
                    margin: MarginPaddingUtil.symmetric(
                        vertical: 23, horizontal: 20),
                    padding: MarginPaddingUtil.symmetric(
                        vertical: 42, horizontal: 37),
                    decoration: BoxDecoration(
                        color: Colors.white,
                        borderRadius: BorderRadius.circular(20.width)),
                    child: Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        TextCommon(
                          "账号被绑定",
                          size: 28.sp,
                          fontWeight: FontWeight.bold,
                        ),
                        40.heightBox,
                        Row(
                          children: [
                            TextCommon(
                              "主账号",
                              size: 28.sp,
                              fontWeight: FontWeight.w500,
                            ),
                            Spacer(),
                            TextCommon(
                              controller.childAccountListBean?.mainAccount ??
                                  "",
                              size: 28.sp,
                              fontWeight: FontWeight.w500,
                            ),
                          ],
                        )
                      ],
                    ),
                  )
              ],
            ),
          ),
          if (controller.childAccountListBean?.subType != 2)
            Container(
              width: Get.width,
              color: Colors.white,
              padding:
                  MarginPaddingUtil.symmetric(vertical: 22, horizontal: 200),
              child: ButtonCommon(
                text: "添加子账号",
                onTap: () {
                  controller.showDialog();
                },
                fontSize: 32.sp,
                fontColor: Colors.white,
                color: Color(0xFFEDC88B),
                borderRadios: 50,
                padding: MarginPaddingUtil.only(top: 25, bottom: 29),
              ),
            )
        ],
      ),
    );
  }
}
